package com.yang;

import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class YangReturnWorldCenterPoint extends JavaPlugin implements Listener {

    FileConfiguration config;

    @Override
    public void onEnable() {
        this.saveDefaultConfig();
        config = this.getConfig();
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    private void playerJoinEvent(PlayerJoinEvent playerJoinEvent){
        String world = config.getString("world");
        double x = config.getDouble("x");
        double y = config.getDouble("y");
        double z = config.getDouble("z");
        if(playerJoinEvent.getPlayer().getWorld().getName().equals(world)){
            Location location = new Location(playerJoinEvent.getPlayer().getWorld(), x, y, z);
            playerJoinEvent.getPlayer().teleport(location);
        }
    }

    @Override
    public void onDisable() {
    }
}
